package cn.stylefeng.guns.modular.bi.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.bi.entity.TransportRegistrationShiftSchedule;
import cn.stylefeng.guns.modular.bi.mapper.TransportRegistrationShiftScheduleMapper;
import cn.stylefeng.guns.modular.bi.model.params.TransportRegistrationShiftScheduleParam;
import cn.stylefeng.guns.modular.bi.model.result.TransportRegistrationShiftScheduleResult;
import  cn.stylefeng.guns.modular.bi.service.TransportRegistrationShiftScheduleService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 临时卡打卡班次表 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2024-07-30
 */
@Service
public class TransportRegistrationShiftScheduleServiceImpl extends ServiceImpl<TransportRegistrationShiftScheduleMapper, TransportRegistrationShiftSchedule> implements TransportRegistrationShiftScheduleService {

    @Override
    public void add(TransportRegistrationShiftScheduleParam param){
        TransportRegistrationShiftSchedule entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportRegistrationShiftScheduleParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportRegistrationShiftScheduleParam param){
        TransportRegistrationShiftSchedule oldEntity = getOldEntity(param);
        TransportRegistrationShiftSchedule newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportRegistrationShiftScheduleResult findBySpec(TransportRegistrationShiftScheduleParam param){
        return null;
    }

    @Override
    public List<TransportRegistrationShiftScheduleResult> findListBySpec(TransportRegistrationShiftScheduleParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportRegistrationShiftScheduleParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportRegistrationShiftScheduleParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportRegistrationShiftSchedule getOldEntity(TransportRegistrationShiftScheduleParam param) {
        return this.getById(getKey(param));
    }


    private TransportRegistrationShiftSchedule getEntity(TransportRegistrationShiftScheduleParam param) {
        TransportRegistrationShiftSchedule entity = new TransportRegistrationShiftSchedule();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
